window.onload=function() {
	getusername();
	getallbrand();
	getmodel();
}

function getallbrand() {
    $.ajax({
      url: 'http://172.18.21.150/ToGo/listBrandAll',
      type: 'post',
      dataType: 'json',
      success:function (result) {
          if(result.status=='200'){
            var data=result.data;
            $('#mid-brand').html('');
            for(var i=0;i<data.length;i++){
            	$('#carbrand').append('<option value='+data[i].brand_name+'>'+data[i].brand_name+'</option>');
            }
          }
      },
      error:function () {
        alert('error');
      }
    });
}

function getmodelsbybrandname(brand_name){
	$.ajax({
		url: 'http://172.18.21.150/ToGo/getModelsByBrandName',
		type: 'post',
		dataType: 'json',
		data: {brand_name: brand_name},
		success:function (result) {
			if(result.status=='200'){
				var models=result.data;
				$('#carkind').html("");
				for (var i = 0; i < models.length; i++) {
					$('#carkind').append('<option value='+models[i].name+'>'+models[i].name+'</option>');
				}
			}
		},
		error:function () {
			alert('error');
		}
	});	
}

function getmodel() {
	$('#carbrand').change(function() {
		getmodelsbybrandname($('#carbrand').val());
	});
}

function uploadcar() {

	$('#user_id').val($.cookie('userid'));
	$('#username').val($.cookie('username'));

      $('#uploadcar').submit();
      alert('上传成功！');
      window.location.reload(true);
}